import fortune
from mastodon import Mastodon

'''
Nur einmal am Anfang clientcred.secret erstellen:

Mastodon.create_app(
     'demospruechebot',
     api_base_url = 'https://botsin.space',
     to_file = 'demospruechebot_clientcred.secret'
)
'''

# Variablen
bot_pfad = 'home/pi/demospruechebot/'
fortunefile = 'demosprueche'
client_secret_file = 'demospruechebot_clientcred.secret'
usercred_secret_file = 'demospruechebot_usercred.secret'
instanz_url = 'https://botsin.space'
mail_adresse = 'XXX@XXX'
login_passwort = 'XXX'

# Objekt erstellen
mastodon = Mastodon(
    client_id = bot_pfad + client_secret_file,
    api_base_url = instanz_url
)

# Login
mastodon.log_in(
    mail_adresse,
    login_passwort,
    to_file = bot_pfad + usercred_secret_file
)

mastodon = Mastodon(
    access_token = bot_pfad + usercred_secret_file,
    api_base_url = instanz_url
)

# fortune erzeugen
troet = fortune.get_random_fortune(bot_pfad + fortunefile)

# Tröten
mastodon.toot(troet)
